<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function override(){
		header('Location: /');
	}

	public function index(){
		$this->load->model('ckmodel');
		$displayData['countArray']=$this->ckmodel->getTypeDeals('Featured',$storeUrl="Home",$start='');
		$displayData['featuredDealsArray']=$this->ckmodel->getTypeDeals('Featured',$storeUrl="Home",$start='0', $end='10');
		$displayData['topDealsArray']=$this->ckmodel->getTypeDeals('TOP',$storeUrl="Home",$start='0', $end='11');
		$displayData['homeBanner']= $this->ckmodel->getBanner();
		$displayData['banner250'] = $this->ckmodel->getRandomBanners();
		$displayData['show'] = 'index';
		$this->load->view('home', $displayData);
	}
	
	public function moreResult($count){
		$this->load->model('ckmodel');
		$end = $count+10;
		$displayData['countArray']=$this->ckmodel->getTypeDeals('Featured',$storeUrl="Home",$start='');
		$displayData['featuredDealsArray']=$this->ckmodel->getTypeDeals('Featured',$storeUrl="Home",$start='0', $end);
		$displayData['topDealsArray']=$this->ckmodel->getTypeDeals('TOP',$storeUrl="Home",$start='0', $end='11');
		$displayData['homeBanner']= $this->ckmodel->getBanner();
		$displayData['banner250'] = $this->ckmodel->getRandomBanners();
		$displayData['show'] = 'index';
		$this->load->view('home', $displayData);
	}
	
	public function dealDetail($dUrl)
	{
		$this->load->model('ckmodel');
		$dUrl = urldecode($dUrl);
		$dealDetailArray = $this->ckmodel->getDealDetail($dUrl);
		if(isset($dealDetailArray) && !empty($dealDetailArray)){
			$displayData['dealDetailArray'] = $dealDetailArray;
			$dId = $dealDetailArray[0]['deals_id'];
			$dCat = $dealDetailArray[0]['deals_category'];
			$dSId = $dealDetailArray[0]['store_id'];
			$displayData['dealSpec'] = $this->ckmodel->getDealSpec($dId);
			$storeUrl = $dealDetailArray[0]['store_url'];
			$topDealsArray=$this->ckmodel->getRelatedDeals($dId, 'TOP',$storeUrl, $start='0', $end='10');
			$count = count($topDealsArray);
			if($count < '10'){
				$end = 10-count($topDealsArray);
				$topDealsArray1=$this->ckmodel->getRelatedDeals($dId, 'Featured',$storeUrl, $start='0', $end);
				$topDealsArray = array_merge($topDealsArray, $topDealsArray1);
			}
			$displayData['topDealsArray'] = $topDealsArray;
			$otherDeals = $this->ckmodel->getOtherDeals($dCat, $dSId, $limit='9');
			$displayData['otherDeals'] = $otherDeals;
			$displayData['banner250'] = $this->ckmodel->getStoreBanners($dSId);
			$this->load->view('deals-page', $displayData);
		}else{
			header('Location: /');
		}
	}
	
	public function redirectPage(){
		$this->load->model('ckmodel');
		$deal_id = $_GET['deal'];
		$store_id = $_GET['store'];
		$displayData['affURL'] = $this->ckmodel->getAffiliateURLByCouponId($deal_id, $store_id);
		$this->load->view('redirect', $displayData);
	}
	
	public function getStoreHome($storeUrl){
		$this->load->model('ckmodel');
		$this->load->helper('cookie');
		$storeDetailsArray = $this->ckmodel->getStoreDetails($storeUrl);
		if (isset($storeDetailsArray) && !empty($storeDetailsArray)){
			$storeName=$storeDetailsArray[0]['store_name'];
			$displayData['storeDetailsArray']=$storeDetailsArray;
			$store_id=$storeDetailsArray[0]['store_id'];
			$displayData['store_id'] = $store_id;
			$displayData['bannersArray']=$this->ckmodel->getStoreBanners($store_id);
			$displayData['storeDealArray']=$this->ckmodel->getStoreDeals($store_id);
			$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
			$cat = $storeDetailsArray[0]['store_cat_id'];
			$topDealsArray=$this->ckmodel->getRelatedDeals('', 'TOP',$storeUrl, $start='0', $end='10');
			$count = count($topDealsArray);
			if($count < '10'){
				$end = 10-count($topDealsArray);
				$topDealsArray1=$this->ckmodel->getRelatedDeals('', 'Featured',$storeUrl, $start='0', $end);
				$topDealsArray = array_merge($topDealsArray, $topDealsArray1);
			}
			$displayData['similarOffersArray']= $topDealsArray;
			$displayData['expiredStoreDealsArray']=$this->ckmodel->getTypeDeals('Expired', $storeUrl);
			$displayData['pageArray']=$displayData['storeDetailsArray'];
			$this->load->view('deals-store-home', $displayData);
		}else{
			header('Location: /');
		}
	}
	
	public function getTopDeals(){
		$this->load->model('ckmodel');
		$displayData['pTab'] = 'top-deals';
		$displayData['bannersArray']=$this->ckmodel->getRandomBanners();
		$displayData['topCouponsArray']=$this->ckmodel->getTypeDeals('TOP',$storeUrl="Home",$start='0', $end='30');
		$pageArray[0]['metatitle']="Top Deals.";
		$pageArray[0]['metakeyword']="top deals";
		$pageArray[0]['metadescription']="Top Offers and Deals.";
		$displayData['pageArray']=$pageArray;
		$this->load->view('deals-top-page', $displayData);
	}
	
	
	
	
	

	public  function getCategoryStores($category){
		$this->load->model('ckmodel');
		$displayData['categoryDetailsArray']=$this->ckmodel->getCategoryDetails($category);
		$categoryId=$displayData['categoryDetailsArray'][0]['category_id'];
		$category_name=$displayData['categoryDetailsArray'][0]['category_name'];
		$metatitle = $displayData['categoryDetailsArray'][0]['metatitle'];
		$metakey = $displayData['categoryDetailsArray'][0]['metakeyword'];
		$metadesc = $displayData['categoryDetailsArray'][0]['metadescription'];
		if($metatitle!=''){
			$pageArray[0]['metatitle']= $metatitle;
		}else{
			$pageArray[0]['metatitle']="$category_name Coupon Codes - Promotion Codes of all online $category_name stores.";
		}
		if($metakey!=''){
			$pageArray[0]['metakeyword']= $metakey;
		}else{
			$cat=strtolower($category_name);
			$pageArray[0]['metakeyword']="$cat, $cat coupon codes, online $cat promo codes, $category discount coupons, $cat promotional codes, online $cat discount coupons";
		}
		if($metadesc!=''){
			$pageArray[0]['metadescription']= $metadesc;
		}else{
			$cat=strtolower($category_name);
			$pageArray[0]['metadescription']="$category_name Discount Coupons - Find Coupon Codes, Promotional Codes of all online $cat stores in India and save your money.";
		}
		$displayData['pageArray']=$pageArray;
		$displayData['category'] = $category;
		$displayData['categoryStoresArray']=$this->ckmodel->getCategoryStores($categoryId);
		$limit=5;
		$displayData['topCatCouponsArray']=$this->ckmodel->getTopCategoryCoupons($categoryId, 0, $limit);
		$count = count($displayData['topCatCouponsArray']);
		if($count<5){
			$limit = 5-$count;
			$displayData['similarOffersArray']=$this->ckmodel->getTopCategoryOffers($categoryId, 0, $limit);
		}
		$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
		//$displayData['bannersArray']=$this->ckmodel->getScrollBanners(0);
		$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
		$this->load->view('ck-category', $displayData);
	}

	public function getAllStores(){
		$this->load->model('ckmodel');
		$pageArray[0]['metatitle']="Coupon Codes - Promotion Codes, Discount Coupons of all stores.";
		$pageArray[0]['metakeyword']="all stores, all stores coupon codes, all stores discount coupons, all stores promotional codes";
		$pageArray[0]['metadescription']="Find Coupon Codes, Discount Coupons, Promotion Codes, Deals and Offers for your all favourite online stores and save money while shopping.";
		$displayData['pageArray']=$pageArray;
		$displayData['allStoresArray']=$this->ckmodel->getAllStores();
		$this->load->view('ck-all-stores', $displayData);
	}
	
	public function getAllCategories(){
		$this->load->model('ckmodel');
		$pageArray[0]['metatitle']="Discount Coupons - Coupon Codes, Promotion Codes of all stores according to categories.";
		$pageArray[0]['metakeyword']="all categories, all categories coupon codes, all categories discount coupons, all categories promotional codes";
		$pageArray[0]['metadescription']="Find Promotion Codes, Coupon Codes, Deals and Offers, Discount Coupons for your all favourite categories and save more while shopping.";
		$displayData['pageArray']=$pageArray;
		$allCatArray = $this->ckmodel->getAllCategories();
		$displayData['allCatArray']= $allCatArray;
		foreach($allCatArray as $temp => $values){
			$catId = $values['category_id'];
			$data['allStoresArray'.$temp]=$this->ckmodel->getCategoryStores($catId, '400');
			$displayData['allStoresArray'] = $data;
		}
		$this->load->view('ck-all-cat', $displayData);
	}

	public function contactUs(){
		$this->load->model('ckmodel');
		$pageArray[0]['metatitle']="Contact Us";
		$pageArray[0]['metakeyword']="Contact Us";
		$pageArray[0]['metadescription']="Contact Us";
		$displayData['pageArray']=$pageArray;
		$this->load->view('ck-contact-us', $displayData);
	}

	public function advertisers(){
		$this->load->model('ckmodel');
		$pageArray[0]['metatitle']="Advertisers";
		$pageArray[0]['metakeyword']="Advertisers";
		$pageArray[0]['metadescription']="Advertisers";
		$displayData['pageArray']=$pageArray;
		$this->load->view('ck-advertisers', $displayData);
	}
	public function submitAdvertiser(){
		$this->load->model('ckmodel');
		$this->ckmodel->addAdvertisers($_POST);
		$pageArray[0]['metatitle']="Advertisers";
		$pageArray[0]['metakeyword']="Advertisers";
		$pageArray[0]['metadescription']="Advertisers";
		$displayData['pageArray']=$pageArray;
		$displayData['message']="Thanks for showing interest in CouponsKart.net.";
		$this->load->view('ck-advertisers', $displayData);
	}

	public function aboutUs(){
		$this->load->model('ckmodel');
		$pageArray[0]['metatitle']="About CouponsKart.net";
		$pageArray[0]['metakeyword']="About CouponsKart.net";
		$pageArray[0]['metadescription']="About CouponsKart.net";
		$displayData['pageArray']=$pageArray;
		$this->load->view('ck-about-us', $displayData);
	}


	public function contacts(){
		$this->load->model('ckmodel');
		$this->ckmodel->contactUs($_POST);
		$displayData['message']="Thanks for showing interest in CouponsKart.net.";
		$pageArray[0]['metatitle']="Contact Us";
		$pageArray[0]['metakeyword']="Contact Us";
		$pageArray[0]['metadescription']="Contact Us";
		$displayData['pageArray']=$pageArray;
		$displayData['newsKeyword']="coupon+codes";
		$this->load->view('ck-contact-us', $displayData);
	}

	public function shareCoupon($a,$b,$c,$d,$e,$f,$g){
		//error_log('>>>>>>>>>.');
		$this->load->model('ckmodel');
		if($e==$f){
			$b=str_replace("%20", " ", $b);
			$c=str_replace("%20", " ", $c);
			$d=str_replace("%20", " ", $d);
			$this->ckmodel->submitCoupon($a,$b,$c,$d);
			$displayData['msg']="Thanks for sharing coupon with CouponsKart.net.";
		}else{
			$displayData['msg']="Captcha must be same.";
		}
		$storeDetailsArray[0]['store_name'] = str_replace("%20", " ", $g);
		$storeDetailsArray[0]['store_id'] = $a;
		$displayData['storeDetailsArray'] = $storeDetailsArray;
		$this->load->view('common/shareCoupons', $displayData);
	}

	public function getStoreDeals($storeUrl){
		$this->load->model('ckmodel');
		$this->load->model('enterprisesmodel');
		$storeDetailsArray = $this->ckmodel->getStoreDeals($storeUrl);
		if (isset($storeDetailsArray) && !empty($storeDetailsArray)){
			$storeName=$storeDetailsArray[0]['store_name'];
			$storeName=ucfirst($storeName);
			$displayData['storeDetailsArray']=$storeDetailsArray;
			$store_id=$displayData['storeDetailsArray'][0]['store_id'];
			$displayData['bannersArray']=$this->ckmodel->getStoreBanners($store_id);
			$limit = 5;
			$displayData['topCatCouponsArray']=$this->ckmodel->getStoreDealCoupons($store_id, $limit);
			$cMonth=date('m');
			$cYear=date('Y');
			$this->ckmodel->updateStoreViews($store_id, $cMonth, $cYear);
			$displayData['bannersArray1']=$this->ckmodel->getRandomBanners();
			$pageArray[0]['metatitle']=$storeDetailsArray[0]['metatitle'];
			$pageArray[0]['metakeyword']=$storeDetailsArray[0]['metakeyword'];
			$pageArray[0]['metadescription']=$storeDetailsArray[0]['metadescription'];
			$displayData['pageArray']=$pageArray;
			$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
			$displayData['relatedDeals'] = $this->enterprisesmodel->getStoreDeals();
			$this->load->view('ck-store-deals', $displayData);
		}else{
			header('Location: /');
		}
	}
	
	public function getAlphaStores($alpha){
		$this->load->model('ckmodel');
		$displayData['alpha']=$alpha;
        $topAlphaArray=array();
        $alphaStoresArray=$this->ckmodel->getAlphaStores($alpha);
        $displayData['alphaStoresArray']=$alphaStoresArray;
        foreach($alphaStoresArray as $temp => $value){
        if($temp<3){
        array_push($topAlphaArray, $value['store_name']);
        }
        }
        $topAlphaArray=implode($topAlphaArray,", ");
		$pageArray[0]['metatitle']="Discount Coupons of ".$topAlphaArray." on CouponsKart.net";
		$pageArray[0]['metakeyword']=$topAlphaArray;
		$pageArray[0]['metadescription']="Find Discount Coupons of ".$topAlphaArray." on CouponsKart.net";
		$displayData['pageArray']=$pageArray;
		$displayData['alphaStoresArray']=$this->ckmodel->getAlphaStores($alpha);
		$displayData['allStoresArray']=$this->ckmodel->getAllStores();
		$displayData['bannersArray']=$this->ckmodel->getStoreBanners(0);
		$displayData['flightsCategoryStoresArray']=$this->ckmodel->getCategoryStores(2);
		$displayData['airlinesCategoryStoresArray']=$this->ckmodel->getCategoryStores(3);
		$displayData['shoppingCategoryStoresArray']=$this->ckmodel->getCategoryStores(6);
		$displayData['dealsCategoryStoresArray']=$this->ckmodel->getCategoryStores(10);
		$displayData['hostingCategoryStoresArray']=$this->ckmodel->getCategoryStores(11);
		$displayData['newsKeyword']="voucher+codes";
		$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
		$this->load->view('ck-alpha-stores', $displayData);
	}

	public function searchStore($tag){
		$this->load->model('ckmodel');
		$tag=str_replace("%20"," ",$tag);
		$displayData['$tag']=$tag;
		$displayData['searchStoreArray']=$this->ckmodel->searchStore($tag);
		$displayData['allStoresArray']=$this->ckmodel->getAllStores();
		if (isset($displayData['searchStoreArray'][0]['store_category_tbl_id'])){
			$category=$displayData['searchStoreArray'][0]['store_category_tbl_id'];
		}else{
			$category=0;
		}
		if (isset($displayData['searchStoreArray'][0]['store_id'])){
			$store_id=$displayData['searchStoreArray'][0]['store_id'];
			$store_url=$displayData['searchStoreArray'][0]['store_url'];
		}else{
			$store_id=0;
		}
		//$displayData['bannersArray']=$this->ckmodel->getScrollBanners(0);
		//$displayData['relatedStoresArray']=$this->ckmodel->getRelatedStores($category, $store_id);
		$tags=ucfirst($tag);
		$pageArray[0]['metatitle']="Search Discount Coupons of all stores similar to word $tags";
		$pageArray[0]['metakeyword']="search stores, search online stores, search coupon codes, $tags promo codes, $tags discount coupons, $tags promotion codes";
		$pageArray[0]['metadescription']="Stores Search - Search Coupon Codes, Discount Coupons, Promotional Codes of all stores similar to word $tags and related stores of $tags.";
		$displayData['pageArray']=$pageArray;
		//$displayData['newsKeyword']=str_replace("-", "+", $tag);
		if($store_id==0){
			header('Location: /');
		}else{
			header('Location: /'.$store_url.'-coupons');
		}
	}

	public function subscribeEmailId($emailId, $storeId,$storeName){
		$emailId=str_replace("%20","@",$emailId);
		$this->load->model('ckmodel');
		$subscribeId=$this->ckmodel->subscribeEmailId($emailId, $storeId,$storeName);
		/*if($subscribeId!=-1){
			echo "success";
		$to = $emailId;
		$subject = "Thank you very much for subscribing to CheapFlightsTo newsletter";
		$message = "Dear Subscriber,".PHP_EOL.PHP_EOL."Thank you very much for subscribing to CheapFlightsTo newsletter.  We will try our best to provide you with the very best and cheapest available offers from different providers from time to time. We will also keep you updated about any special offers that we come across and could be beneficial to you.  Please keep visiting www.CheapFlightsTo.in and enjoy your travel.".PHP_EOL."In case, you wish to contact us, Please email us your queries at info@cheaptravelsto.co.uk.".PHP_EOL.PHP_EOL."CheapFlightsTo Team";
		$from = "cheapflightsto.in@gmail.com";
		$headers = "From:" . $from;
		mail($to,$subject,$message,$headers);
		$to = "info@cheaptravelto.co.uk";
		$subject = "New Subscriber on www.cheapflightsto.in";
		$message = "Hi,".PHP_EOL.PHP_EOL."Email Id of the new subscriber subscribed on our website www.cheapflightsto.in is *$emailId*.".PHP_EOL.PHP_EOL."CheapFlightsTo Team";
		$from = "cheapflightsto.in@gmail.com";
		$headers = "From:" . $from;
		mail($to,$subject,$message,$headers);
		}else{
		echo "failure";
		}*/
	}

	public function rateYourEndure($storeId, $ratingStar){
		$this->load->model('ckmodel');
		$ipAddr = $_SERVER["REMOTE_ADDR"];
		$storeDetailsArray = $this->ckmodel->getStoreDetailsById($storeId);
		$displayData['storeName'] = $storeDetailsArray[0]['store_name'];
		$displayData['store_id'] = $storeId;
		$displayData['rated'] = true;
		$displayData['ratingsArray'] = $this->ckmodel->rateYourEndure($storeId, $ratingStar, $ipAddr);
		$this->load->view('common/starRatings', $displayData);
	}

	public function getBankOffers($bankUrl){
		$this->load->model('ckmodel');
		$bankDetailsArray = $this->ckmodel->getBankDetailsByURL($bankUrl);
		$displayData['bankDetailsArray']=$bankDetailsArray;
		$bankId=$bankDetailsArray[0]['bank_id'];
		$bankName=$bankDetailsArray[0]['bank_name'];
		$bankWebUrl=$bankDetailsArray[0]['bank_weburl'];
		$currentMonth=date('F');
		$currentYear=date('Y');
		$country=$bankDetailsArray[0]['bank_country'];
		$pageArray[0]['metatitle']="$bankName Offers $country - $bankName Discount Offers at Couponskart.net";
		$pageArray[0]['metakeyword']="$bankName, $bankWebUrl, $bankName offers, $bankName coupon codes, $bankName discount coupons, $bankName Promotion codes, discount codes, voucher code, deals, promo codes.";
		$pageArray[0]['metadescription']="$bankName Offers - Get benefitted by purchasing products at discounted rates using $bankName Offers at CouponsKart.net";
		$displayData['pageArray']=$pageArray;
		$allBankCouponsArray = $this->ckmodel->getAllBankCoupon($bankId);
		$displayData['allBankCouponsArray'] = $allBankCouponsArray;
		$allBankOffersArray = $this->ckmodel->getAllBankOffer($bankId);
		$displayData['allBankOffersArray'] = $allBankOffersArray;
		$countC = count($allBankCouponsArray);
		$countO = count($allBankOffersArray);
		$total = $countC+$countO;
		if($total<10){
			$limit = 10-$total;
			$displayData['allBankRelatedArray'] = $this->ckmodel->getRelatedBankCoupons($bankId, $limit);
			$count = count($displayData['allBankRelatedArray']);
			if($count<10){
				$limit = 10-$count;
				$displayData['allRelatedBankOffers'] = $this->ckmodel->getRelatedBankOffers($bankId, $limit);
			}
		}
		$displayData['othetBanksArray']=$this->ckmodel->getAllBanksById($bankId);
		$displayData['bannersArray']=$this->ckmodel->getRandomBanners();
		$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
		$displayData['similarOffersArray']=$this->ckmodel->getOffersWithoutBank();
		$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
		$this->load->view('ck-bank-page', $displayData);
	}
	 
	public function getOccasion($occasionUrl){
		$this->load->model('ckmodel');
		$occasionDetailsArray = $this->ckmodel->getOccasionDetails($occasionUrl);
		if (isset($occasionDetailsArray) && !empty($occasionDetailsArray)){
			$occasionName=$occasionDetailsArray[0]['occasion_name'];
			$occasionName=ucfirst($occasionName);
			$occasion_id = $occasionDetailsArray[0]['occasion_id'];
			$occasionCouponArray = $this->ckmodel->getAllOccasionCoupons($occasion_id);
			$displayData['occasionCouponArray'] = $occasionCouponArray;
			$occasionOfferArray = $this->ckmodel->getAllOccasionOffers($occasion_id);
			$displayData['occasionOfferArray'] = $occasionOfferArray;
			$countC = count($occasionCouponArray);
			$countO = count($occasionOfferArray);
			$total = $countC+$countO;
			if($total<10){
				$limit = 10-$total;
				$displayData['allOccasionRelatedArray'] = $this->ckmodel->getRelatedOccasionCoupons($occasion_id, $limit);
				$count = count($displayData['allOccasionRelatedArray']);
				if($count<10){
					$limit = 10-$count;
					$displayData['allRelatedOccasionOffers'] = $this->ckmodel->getRelatedOccasionOffers($occasion_id, $limit);
				}
			}
			$displayData['occasionDetailsArray']=$occasionDetailsArray;
			$displayData['similarOffersArray'] = $this->ckmodel->getSimilarOccasion($occasion_id);
			$displayData['bannersArray']=$this->ckmodel->getRandomBanners();
			$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
			$pageArray[0]['metatitle']="Latest $occasionName 2013 Special Offers and Deals only on CouponsKart.net.";
			$pageArray[0]['metakeyword']="$occasionName special, $occasionName offers, $occasionName coupons, $occasionName deals";
			$pageArray[0]['metadescription']="$occasionName Special Offers and Deals - Get all latest $occasionName 2013 special coupons, offers and deals only on CouponsKart.net.";
			$displayData['pageArray']=$pageArray;
			$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
			$this->load->view('ck-occasion-page', $displayData);
		}else{
			header('Location: /');
		}
	}
	 
	public function getCouponDetail($storeUrl, $couponUrl){
		$this->load->model('ckmodel');
		 
		$couponDetail = $this->ckmodel->getCouponDetail($couponUrl);
		//error_log(count($couponDetail));
		if (isset($couponDetail) && !empty($couponDetail)){
			$displayData['couponDetail'] = $couponDetail;
			$storeDetailsArray = $this->ckmodel->getStoreDetails($storeUrl);
			$storeName=$storeDetailsArray[0]['store_name'];
			$displayData['storeName'] = $storeName;
			$displayData['rated'] = false;
			$storeName=ucfirst($storeName);
			$displayData['storeDetailsArray']=$storeDetailsArray;
			$store_id=$displayData['storeDetailsArray'][0]['store_id'];
			$displayData['store_id'] = $store_id;
			$ipAddr = $_SERVER["REMOTE_ADDR"];
			$displayData['ratingsArray'] = $this->ckmodel->rateYourEndure($store_id, 0, $ipAddr);
			$displayData['storeSimilarCoupon'] = $this->ckmodel->getStoreSimilarCoupon($couponUrl, $store_id);
			$displayData['bankOfferByStore'] = $this->ckmodel->getBankOfferByStore($store_id);
			$displayData['bannersArray']=$this->ckmodel->getStoreBanners($store_id);
			$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
			$cat = $storeDetailsArray[0]['store_cat_id'];
			$displayData['topCouponsArray']=$this->ckmodel->getTopCoupons($couponUrl);
			$displayData['allStoresArray']=$this->ckmodel->getAllStores();
			$displayData['breadcrumCat'] = $this->ckmodel->getBreadcrumCat($cat);
			//var_dump($couponDetail);
			$pageArray[0]['metatitle']=$storeName." Top Coupon - ".$couponDetail[0]['coupon_name'];
			$pageArray[0]['metakeyword']="";
			$pageArray[0]['metadescription']="";
			$displayData['pageArray']=$pageArray;
			$cMonth=date('m');
			$cYear=date('Y');
			$this->ckmodel->updateStoreViews($store_id, $cMonth, $cYear);
			$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
			$this->load->view('ck-detail-page', $displayData);
		}else{
			header('Location: /');
		}
	}
	 
	public function getDeals(){
		$this->load->model('ckmodel');
		$this->load->model('enterprisesmodel');
		$allDealsArray = $this->enterprisesmodel->getStoreDeals();
		//var_dump($allDealsArray);die();
		$displayData['allDealsArray'] = $allDealsArray;
		$displayData['bannersArray']=$this->ckmodel->getRandomBanners();
		$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
		$couponUrl = '';
		$displayData['topCouponsArray']=$this->ckmodel->getTopDealsCoupons($allDealsArray, '5');
		$pageArray[0]['metatitle']="Discount coupons for sales , offers , deals , promotions on online shopping e commerce sites in India.";
		$pageArray[0]['metakeyword']="Discount coupons in India , Coupon code , Promotion code , Flight Coupons , Online shopping discount , Online shopping in India , Snapdeal Coupons , Yatra Coupons , Flipkart Coupons , Lenskart Coupons , Ola Cabs Coupons ,online sales";
		$pageArray[0]['metadescription']="Money saving deals , sales offers upto 50% off , free offers like Buy one Get one free and other popular deals , discount coupons are available at Yatra , Myntra , Snapdeal , Flipkart , Ola Cabs , Lenskart , Jet Airways .Get flight coupons , food coupons , hotel coupons , taxi coupons , flight deals, baby items deals at Couponskart.net.";
		$displayData['pageArray']=$pageArray;
		$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
		$displayData['curTab'] = 'deals';
		$this->load->view('ck-all-deals', $displayData);
	}
	
	public function getOccasions(){
		$this->load->model('ckmodel');
		$displayData['bannersArray']=$this->ckmodel->getRandomBanners();
		$displayData['allCategoriesArray']=$this->ckmodel->getAllCategories();
		$couponUrl = '';
		$allOccasion = $this->ckmodel->getAllOccasion();
		$displayData['allOccasion'] = $allOccasion;
		$limit = 5;
		$displayData['allOccasionRelatedArray'] = $this->ckmodel->getRelatedOccasionCoupons($occasion_id='', $limit);
		$count = count($displayData['allOccasionRelatedArray']);
		if($count<5){
			$limit = 5-$count;
			$displayData['allRelatedOccasionOffers'] = $this->ckmodel->getRelatedOccasionOffers($occasion_id='', $limit);
		}
		$displayData['topCouponsArray']=$this->ckmodel->getTopCoupons($couponUrl, '5');
		$pageArray[0]['metatitle']="Shop with discount coupons for diwali gifts , dusshera gifts , valentine day gifts - Online shopping with coupons and coupon codes for gifts in India.";
		$pageArray[0]['metakeyword']="discount coupons , gift coupons , gift vouchers , diwali gifts , diwali coupons , dusshera coupons, holi coupons , christmas coupons , new year coupons , womens day coupons , friendship day gifts , friendship day coupons , valentine day coupons";
		$pageArray[0]['metadescription']="Special offers and mega sales with discount coupons on diwali gifts , dusshera ,holi,christmas, mothers day , fathers day , friendship day , republic day ,new year ,independence day ,women day .Use coupon code for promotions on all gifts , vouchers and online shopping for festivals in India.";
		$displayData['pageArray']=$pageArray;
		$displayData['popupOffer'] = $this->ckmodel->getPopupOffer();
		$this->load->view('ck-all-occasions', $displayData);
	}
	
	public function getCouponsApi()
	{
		$this->load->model('ckmodel');
		$this->load->model('enterprisesmodel');
		if($_GET['type'] == 'topcpns')
		{
			$couponsArray = $this->ckmodel->getTopCoupons($couponUrl='');
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('topcpn'=>$couponsArray));
			echo $xml;
			/*$myFile="topcpn.json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);*/
		}
		if($_GET['type'] == 'allcat')
		{
			$category = $this->ckmodel->getAllCategories();
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('allcat'=>$category));
			echo $xml;
			/*$myFile="allcat.json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);*/
		}
		if($_GET['type'] == 'cat' && $_GET['cat'])
		{
			$cat = $_GET['cat'];
			$category = $this->ckmodel->getCategoryStores($cat);
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('cat'=>$category));
			echo $xml;
			/*$myFile="cat-".$cat.".json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);*/
		}
		if($_GET['type'] == 'allstore' && $_GET['alpha'])
		{
			$alpha = $_GET['alpha'];
			$alphaStoresArray=$this->ckmodel->getAlphaStores($alpha);
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('allstore'=>$alphaStoresArray));
			echo $xml;
			/*$myFile="store-".$alpha.".json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);*/
		}
		if($_GET['type'] == 'store' && $_GET['alpha'])
		{
			$alpha = $_GET['alpha'];
			$store = $this->ckmodel->getStoreDetails($alpha);
			$storeDetailsArray = $this->ckmodel->getTopCategoryCoupons($store[0]['store_cat_id'], $store[0]['store_id'], $limit='40');
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('store'=>$storeDetailsArray));
			echo $xml;
			$myFile="store-".$alpha.".json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);
		}
		if($_GET['type'] == 'search' && $_GET['store'])
		{
			$alpha = $_GET['store'];
			$store = $this->ckmodel->getStoreDetails($alpha);
			$storeDetailsArray = $this->ckmodel->getTopCategoryCoupons($store[0]['store_cat_id'], $store[0]['store_id'], $limit='40');
			header('<?xml version="1.0" encoding="UTF-8"?>');
			header('Content-type: application/json');
			$xml =  json_encode(array('search'=>$storeDetailsArray));
			echo $xml;
			$myFile="search-".$alpha.".json";
			$fh = fopen($myFile, 'w') or die("can't open file");
			fwrite($fh, $xml);
			fclose($fh);
		}
	}
	 
	public function generateSiteMap()
	{
		$this->load->model('ckmodel');
		$this->load->model('enterprisesmodel');
		
		$pTabSelection='sitemap.xml';
		$displayData['pTabSelection']=$pTabSelection;
		 
		$store = $this->ckmodel->getAllStores();
		$category = $this->ckmodel->getAllCategories();
		$banks = $this->ckmodel->getAllBanks();
		$occasions = $this->ckmodel->getAllOccasion();
		$topcoupons = $this->ckmodel->getTopCoupons();
		$allDealsArray = $this->enterprisesmodel->getStoreDeals();

		$xmlBuild = '';
		$xmlBuild .= '<?xml version="1.0" encoding="UTF-8"?>';
		$xmlBuild .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/all-stores</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/about-us</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/contact-us</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/advertisers</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/top-coupons</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/deals</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/all-categories</loc></url>';
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/all-occasions</loc></url>';
		 
		foreach($store as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/'.$values['store_url'].'-coupons</loc></url>';
		}
		foreach($category as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/'.$values['category_url'].'-coupon-codes</loc></url>';
		}
		$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/all-stores/0-9</loc></url>';
		for($a=65;$a<=90;$a++){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/all-stores/'.chr($a).'</loc></url>';
		}
		foreach($banks as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/'.$values['bank_url'].'-offers</loc></url>';
		}
		foreach($occasions as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/'.$values['occasion_url'].'-offers-and-deals</loc></url>';
		}
		foreach($topcoupons as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/top-coupons/'.$values['store_url'].'/'.$values['coupon_url'].'</loc></url>';
		}
		foreach($allDealsArray as $rows => $values){
			$xmlBuild .= '<url><loc>http://'.$_SERVER['HTTP_HOST'].'/'.$values['store_url'].'-deals</loc></url>';
		}
		
		
		$xmlBuild .= '</urlset>';
		$myFile="sitemap.xml";
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $xmlBuild);
		fclose($fh);

		$displayData['msg'] = 'Your Sitemap.xml has been refreshed..';
		$this->load->view('sitemap', $displayData);
}

	

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
